const Treeview = {};
/**
 * 将数据库中树列表转换成树形对象
 * @param {array} arrays 树形数据数组
 * @return {object} 对应的树形JSON对象
 */
Treeview.fromArray = (arrays) => {
    let translator = (data, pid) => {
        var tree = [];
        arrays.forEach(item => {
            if (item.pid == pid) {
                var temp = translator(data, item.id);
                item.children = temp.length > 0 ? temp : undefined;
                tree.push(item);
            }
        });
        return tree;
    };
    //返回最终的结果
    return translator(arrays, "0");
}

export default Treeview;